package work.chenbo.zmqc.business.channe.model;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 渠道规则 全局规则配置实体类型
 * @author ChenBo
 * @className ChanneGlobalRuleVO
 * @date 2020/11/9
 */
@Data
@ApiModel(value = "全局规则配置实体",description = "全局规则配置实体类型")
public class ChannelGlobalRuleVO implements Serializable {


    @ApiModelProperty(value = "渠道规则ID")
    private Integer roleId;

    @ApiModelProperty(value = "最外层规则逻辑关系")
    private Integer Logic;

    @ApiModelProperty(value = "规则集合")
    private List<FirstRuleVO> ruleList;


    @Data
    @ApiModel(value = "规则集合",description = "一组规则集合")
    public static class  FirstRuleVO implements Serializable {

        @ApiModelProperty(value = "该组规则集合与其他组逻辑关系")
        private Integer Logic;

        @ApiModelProperty(value = "规则列表")
        private List<FirstRuleVO.RoleVO> ruleList;

        @Data
        @ApiModel(value = "规则对象")
        public static class RoleVO implements Serializable {
            @ApiModelProperty(value = "规则ID")
            private Integer id;
            @ApiModelProperty(value = "该规的逻辑规则")
            private Integer valueLogic;
            @ApiModelProperty(value = "规则编码")
            private String code;
            @ApiModelProperty(value = "规则值")
            private String value;
            @ApiModelProperty(value = "规则输入类型")
            private Integer type;
            @ApiModelProperty(value = "该规则可选的逻辑列表")
            private List<SelectVO> valueLogicList;
        }

    }


    public static ChannelGlobalRuleVO getJSONObject(String jsonString){
        ChannelGlobalRuleVO channelGlobalRuleVO = JSONObject.parseObject(jsonString, ChannelGlobalRuleVO.class);
        return channelGlobalRuleVO;
    }




    @Data
    @AllArgsConstructor
    public static class SelectVO{
        private String text;
        private Integer value;
    }


    public static List<SelectVO> getValueLogicList(){
        ArrayList<SelectVO> selectVOS = new ArrayList<SelectVO>() {{
            add(new SelectVO("等于",1));
            add(new SelectVO("不等于",2));
            add(new SelectVO("包含",3));
            add(new SelectVO("不包含",4));
            add(new SelectVO("为空",5));
            add(new SelectVO("不为空",6));
            add(new SelectVO("正则匹配",7));
            add(new SelectVO("正则不匹配",8));
        }};
        return selectVOS;
    }

    public static List<SelectVO> getLogicList(){
        ArrayList<SelectVO> selectVOS = new ArrayList<SelectVO>() {{
            add(new SelectVO("且",0));
            add(new SelectVO("或",1));
        }};
        return selectVOS;
    }

}
